<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>星元空间 - 入口管理原型</title>
    <link rel="stylesheet" href="assets/css/common.css">
    <style>
        .page-container {
            max-width: 1400px;
            margin: 0 auto;
            padding: var(--spacing-xxl);
        }

        .page-header {
            margin-bottom: var(--spacing-xxl);
        }

        .page-header h1 {
            font-size: 24px;
            color: var(--color-text-primary);
            margin-bottom: 8px;
        }

        .page-header p {
            color: var(--color-text-secondary);
            font-size: 14px;
        }

        .toolbar {
            display: flex;
            gap: var(--spacing-md);
            margin-bottom: var(--spacing-xxl);
            flex-wrap: wrap;
        }

        .search-wrapper {
            flex: 1;
            min-width: 200px;
            position: relative;
        }

        .search-icon {
            position: absolute;
            left: 12px;
            top: 50%;
            transform: translateY(-50%);
            color: var(--color-text-placeholder);
        }

        .search-input {
            width: 100%;
            padding-left: 36px;
        }

        .view-toggle {
            display: flex;
            gap: 4px;
            background: var(--color-bg-white);
            padding: 4px;
            border-radius: var(--radius-sm);
            border: 1px solid var(--color-border-base);
        }

        .view-toggle button {
            padding: 8px 12px;
            border: none;
            background: transparent;
            cursor: pointer;
            border-radius: var(--radius-sm);
            color: var(--color-text-regular);
        }

        .view-toggle button.active {
            background: var(--color-bg);
            color: var(--color-primary);
        }

        .filter-select {
            min-width: 150px;
        }

        /* 统计卡片 */
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: var(--spacing-lg);
            margin-bottom: var(--spacing-xxl);
        }

        .stat-card {
            background: var(--color-bg-white);
            border-radius: var(--radius-md);
            padding: var(--spacing-xxl);
            text-align: center;
            box-shadow: var(--shadow-sm);
        }

        .stat-value {
            font-size: 32px;
            font-weight: 600;
            margin-bottom: 8px;
        }

        .stat-label {
            color: var(--color-text-secondary);
            font-size: 14px;
        }

        /* 入口卡片网格 */
        .entries-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: var(--spacing-lg);
        }

        .entry-card {
            background: var(--color-bg-white);
            border: 1px solid var(--color-border-lighter);
            border-radius: var(--radius-md);
            padding: var(--spacing-xxl);
            box-shadow: var(--shadow-sm);
            transition: all 0.3s;
        }

        .entry-card:hover {
            border-color: var(--color-primary);
            box-shadow: var(--shadow-md);
            transform: translateY(-2px);
        }

        .entry-header {
            display: flex;
            justify-content: space-between;
            align-items: start;
            margin-bottom: var(--spacing-md);
        }

        .entry-info {
            display: flex;
            align-items: center;
            gap: var(--spacing-md);
            flex: 1;
        }

        .entry-icon {
            width: 48px;
            height: 48px;
            background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-active) 100%);
            border-radius: var(--radius-md);
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 24px;
            flex-shrink: 0;
        }

        .entry-details h3 {
            font-size: 16px;
            color: var(--color-text-primary);
            margin-bottom: 4px;
        }

        .entry-category {
            display: inline-block;
            padding: 2px 8px;
            background: var(--color-bg);
            color: var(--color-text-regular);
            border-radius: 12px;
            font-size: 12px;
        }

        .entry-menu {
            position: relative;
        }

        .menu-btn {
            width: 32px;
            height: 32px;
            border: none;
            background: transparent;
            cursor: pointer;
            border-radius: var(--radius-sm);
            display: flex;
            align-items: center;
            justify-content: center;
            color: var(--color-text-regular);
        }

        .menu-btn:hover {
            background: var(--color-bg);
        }

        .dropdown-menu {
            position: absolute;
            top: 100%;
            right: 0;
            background: var(--color-bg-white);
            border: 1px solid var(--color-border-base);
            border-radius: var(--radius-sm);
            box-shadow: var(--shadow-md);
            min-width: 120px;
            z-index: 100;
            display: none;
            margin-top: 4px;
        }

        .dropdown-menu.show {
            display: block;
        }

        .dropdown-item {
            padding: 8px 16px;
            cursor: pointer;
            font-size: 14px;
            color: var(--color-text-primary);
            display: flex;
            align-items: center;
            gap: 8px;
            transition: background 0.2s;
        }

        .dropdown-item:hover {
            background: var(--color-bg);
        }

        .dropdown-item.danger {
            color: var(--color-danger);
        }

        .entry-description {
            color: var(--color-text-secondary);
            font-size: 14px;
            margin-bottom: var(--spacing-md);
            line-height: 1.5;
        }

        .entry-footer {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding-top: var(--spacing-md);
            border-top: 1px solid var(--color-border-lighter);
        }

        .entry-url {
            color: var(--color-text-secondary);
            font-size: 12px;
            flex: 1;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .entry-status {
            display: inline-block;
            padding: 2px 8px;
            border-radius: 12px;
            font-size: 12px;
        }

        .entry-status.active {
            background: #F6FFED;
            color: var(--color-success);
        }

        .entry-status.inactive {
            background: var(--color-bg);
            color: var(--color-text-secondary);
        }

        /* 对话框 */
        .modal-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.5);
            z-index: 1000;
            display: none;
            align-items: center;
            justify-content: center;
        }

        .modal-overlay.show {
            display: flex;
        }

        .modal {
            background: var(--color-bg-white);
            border-radius: var(--radius-lg);
            width: 90%;
            max-width: 600px;
            max-height: 90vh;
            overflow-y: auto;
            box-shadow: var(--shadow-lg);
            animation: modalSlideIn 0.3s ease-out;
        }

        @keyframes modalSlideIn {
            from {
                transform: translateY(-20px);
                opacity: 0;
            }
            to {
                transform: translateY(0);
                opacity: 1;
            }
        }

        .modal-header {
            padding: var(--spacing-xxl);
            border-bottom: 1px solid var(--color-border-lighter);
        }

        .modal-header h2 {
            font-size: 20px;
            color: var(--color-text-primary);
            margin-bottom: 4px;
        }

        .modal-header p {
            color: var(--color-text-secondary);
            font-size: 14px;
        }

        .modal-body {
            padding: var(--spacing-xxl);
        }

        .modal-footer {
            padding: var(--spacing-xxl);
            border-top: 1px solid var(--color-border-lighter);
            display: flex;
            justify-content: flex-end;
            gap: var(--spacing-md);
        }

        .form-group {
            margin-bottom: var(--spacing-lg);
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: var(--color-text-primary);
            font-size: 14px;
        }

        .form-group input,
        .form-group select,
        .form-group textarea {
            width: 100%;
        }

        .form-group textarea {
            min-height: 80px;
            resize: vertical;
        }

        .empty-state {
            text-align: center;
            padding: var(--spacing-xxxl) * 2;
            color: var(--color-text-secondary);
        }

        /* 移动端适配 */
        @media (max-width: 768px) {
            .page-container {
                padding: var(--spacing-md);
            }

            .page-header h1 {
                font-size: 20px;
            }

            .page-header p {
                font-size: 13px;
            }

            .stats-grid {
                grid-template-columns: repeat(2, 1fr);
                gap: var(--spacing-md);
            }

            .stat-card {
                padding: var(--spacing-md);
            }

            .stat-value {
                font-size: 24px;
            }

            .stat-label {
                font-size: 12px;
            }

            .entries-grid {
                grid-template-columns: 1fr;
                gap: var(--spacing-md);
            }

            .entry-card {
                padding: var(--spacing-md);
            }

            .toolbar {
                flex-direction: column;
                gap: var(--spacing-md);
            }

            .search-wrapper {
                width: 100%;
            }

            .search-input {
                width: 100%;
            }

            .filter-select {
                width: 100%;
            }

            .toolbar .btn {
                width: 100%;
            }

            .view-toggle {
                display: none;
            }

            .modal {
                width: 95%;
                max-width: 95%;
                margin: 20px auto;
                max-height: 90vh;
                overflow-y: auto;
            }

            .modal-header {
                padding: var(--spacing-lg);
            }

            .modal-body {
                padding: var(--spacing-lg);
            }

            .modal-footer {
                padding: var(--spacing-lg);
                flex-direction: column-reverse;
                gap: var(--spacing-sm);
            }

            .modal-footer .btn {
                width: 100%;
            }
        }

        /* 小屏幕手机 */
        @media (max-width: 480px) {
            .stats-grid {
                grid-template-columns: 1fr;
            }

            .entry-header {
                flex-direction: column;
                align-items: flex-start;
                gap: var(--spacing-sm);
            }

            .entry-menu {
                align-self: flex-end;
            }

            .entry-footer {
                flex-direction: column;
                gap: var(--spacing-sm);
                align-items: flex-start;
            }
        }
    </style>
</head>
<body>
    <div class="page-container">
        <div class="page-header">
            <h1>系统入口管理</h1>
            <p>集中管理所有系统入口配置</p>
        </div>

        <div class="toolbar">
            <div class="search-wrapper">
                <svg class="search-icon" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                    <circle cx="11" cy="11" r="8"></circle>
                    <path d="m21 21-4.35-4.35"></path>
                </svg>
                <input type="text" class="input search-input" placeholder="搜索系统..." id="searchInput">
            </div>
            <div class="view-toggle">
                <button class="active" data-view="grid">网格</button>
                <button data-view="list">列表</button>
            </div>
            <select class="input filter-select" id="categoryFilter">
                <option value="all">全部分类</option>
                <option value="业务系统">业务系统</option>
                <option value="协作工具">协作工具</option>
                <option value="管理系统">管理系统</option>
            </select>
            <button class="btn btn-primary" onclick="openAddModal()">
                + 添加入口
            </button>
        </div>

        <!-- 统计卡片 -->
        <div class="stats-grid">
            <div class="stat-card">
                <div class="stat-value" style="color: var(--color-primary);" id="totalCount">6</div>
                <div class="stat-label">总入口数</div>
            </div>
            <div class="stat-card">
                <div class="stat-value" style="color: var(--color-success);" id="activeCount">6</div>
                <div class="stat-label">启用中</div>
            </div>
            <div class="stat-card">
                <div class="stat-value" style="color: var(--color-warning);">3</div>
                <div class="stat-label">分类数</div>
            </div>
            <div class="stat-card">
                <div class="stat-value" style="color: var(--color-danger);">156</div>
                <div class="stat-label">今日访问</div>
            </div>
        </div>

        <!-- 入口列表 -->
        <div class="entries-grid" id="entriesGrid">
            <!-- 入口卡片将通过 JavaScript 动态生成 -->
        </div>

        <div class="empty-state" id="emptyState" style="display: none;">
            <p>没有找到匹配的系统入口</p>
        </div>
    </div>

    <!-- 添加/编辑对话框 -->
    <div class="modal-overlay" id="modalOverlay" onclick="closeModal(event)">
        <div class="modal" onclick="event.stopPropagation()">
            <div class="modal-header">
                <h2 id="modalTitle">添加入口</h2>
                <p>配置系统入口的基本信息和访问参数</p>
            </div>
            <div class="modal-body">
                <form id="entryForm">
                    <div class="form-group">
                        <label for="entryName">系统名称 *</label>
                        <input type="text" id="entryName" class="input" placeholder="例如：ERP系统" required>
                    </div>
                    <div class="form-group">
                        <label for="entryUrl">访问地址 *</label>
                        <input type="url" id="entryUrl" class="input" placeholder="https://example.com" required>
                    </div>
                    <div class="form-group">
                        <label for="entryCategory">分类</label>
                        <select id="entryCategory" class="input">
                            <option value="业务系统">业务系统</option>
                            <option value="协作工具">协作工具</option>
                            <option value="管理系统">管理系统</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="entryIcon">图标（Emoji）</label>
                        <input type="text" id="entryIcon" class="input" placeholder="📊">
                    </div>
                    <div class="form-group">
                        <label for="entryDescription">描述</label>
                        <textarea id="entryDescription" class="input" placeholder="简要描述系统功能"></textarea>
                    </div>
                    <div class="form-group">
                        <label for="entryStatus">状态</label>
                        <select id="entryStatus" class="input">
                            <option value="active">启用</option>
                            <option value="inactive">禁用</option>
                        </select>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-secondary" onclick="closeModal()">取消</button>
                <button class="btn btn-primary" onclick="saveEntry()">保存</button>
            </div>
        </div>
    </div>

    <script src="assets/js/common.js"></script>
    <script>
        // 入口数据
        let entries = [
            { id: 1, name: 'ERP系统', url: 'https://erp.company.com', category: '业务系统', icon: '📊', description: '企业资源规划系统', status: 'active' },
            { id: 2, name: 'CRM系统', url: 'https://crm.company.com', category: '业务系统', icon: '👥', description: '客户关系管理系统', status: 'active' },
            { id: 3, name: 'OA系统', url: 'https://oa.company.com', category: '协作工具', icon: '📝', description: '办公自动化系统', status: 'active' },
            { id: 4, name: 'HR系统', url: 'https://hr.company.com', category: '管理系统', icon: '👔', description: '人力资源管理系统', status: 'active' },
            { id: 5, name: '财务系统', url: 'https://finance.company.com', category: '业务系统', icon: '💰', description: '财务管理系统', status: 'active' },
            { id: 6, name: '项目管理', url: 'https://pm.company.com', category: '协作工具', icon: '📋', description: '项目协作平台', status: 'active' },
        ];

        let editingId = null;

        // 渲染入口列表
        function renderEntries() {
            const grid = document.getElementById('entriesGrid');
            const emptyState = document.getElementById('emptyState');
            const searchQuery = document.getElementById('searchInput').value.toLowerCase();
            const categoryFilter = document.getElementById('categoryFilter').value;

            const filtered = entries.filter(entry => {
                const matchesSearch = entry.name.toLowerCase().includes(searchQuery) ||
                    entry.description.toLowerCase().includes(searchQuery);
                const matchesCategory = categoryFilter === 'all' || entry.category === categoryFilter;
                return matchesSearch && matchesCategory;
            });

            if (filtered.length === 0) {
                grid.style.display = 'none';
                emptyState.style.display = 'block';
            } else {
                grid.style.display = 'grid';
                emptyState.style.display = 'none';
                grid.innerHTML = filtered.map(entry => `
                    <div class="entry-card">
                        <div class="entry-header">
                            <div class="entry-info">
                                <div class="entry-icon">${entry.icon}</div>
                                <div class="entry-details">
                                    <h3>${entry.name}</h3>
                                    <span class="entry-category">${entry.category}</span>
                                </div>
                            </div>
                            <div class="entry-menu">
                                <button class="menu-btn" onclick="toggleMenu(event)">
                                    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor">
                                        <circle cx="12" cy="12" r="1"></circle>
                                        <circle cx="12" cy="5" r="1"></circle>
                                        <circle cx="12" cy="19" r="1"></circle>
                                    </svg>
                                </button>
                                <div class="dropdown-menu">
                                    <div class="dropdown-item" onclick="viewEntry(${entry.id})">
                                        <span>👁️</span>
                                        <span>访问</span>
                                    </div>
                                    <div class="dropdown-item" onclick="editEntry(${entry.id})">
                                        <span>✏️</span>
                                        <span>编辑</span>
                                    </div>
                                    <div class="dropdown-item danger" onclick="deleteEntry(${entry.id})">
                                        <span>🗑️</span>
                                        <span>删除</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="entry-description">${entry.description}</div>
                        <div class="entry-footer">
                            <div class="entry-url">${entry.url}</div>
                            <span class="entry-status ${entry.status}">
                                ${entry.status === 'active' ? '已启用' : '已禁用'}
                            </span>
                        </div>
                    </div>
                `).join('');
            }

            // 更新统计
            document.getElementById('totalCount').textContent = entries.length;
            document.getElementById('activeCount').textContent = entries.filter(e => e.status === 'active').length;
        }

        // 切换菜单
        function toggleMenu(event) {
            event.stopPropagation();
            const menus = document.querySelectorAll('.dropdown-menu');
            menus.forEach(menu => menu.classList.remove('show'));
            event.currentTarget.nextElementSibling.classList.toggle('show');
        }

        // 点击外部关闭菜单
        document.addEventListener('click', () => {
            document.querySelectorAll('.dropdown-menu').forEach(menu => menu.classList.remove('show'));
        });

        // 查看入口
        function viewEntry(id) {
            const entry = entries.find(e => e.id === id);
            window.open(entry.url, '_blank');
        }

        // 编辑入口
        function editEntry(id) {
            const entry = entries.find(e => e.id === id);
            editingId = id;
            document.getElementById('modalTitle').textContent = '编辑入口';
            document.getElementById('entryName').value = entry.name;
            document.getElementById('entryUrl').value = entry.url;
            document.getElementById('entryCategory').value = entry.category;
            document.getElementById('entryIcon').value = entry.icon;
            document.getElementById('entryDescription').value = entry.description;
            document.getElementById('entryStatus').value = entry.status;
            document.getElementById('modalOverlay').classList.add('show');
        }

        // 删除入口
        function deleteEntry(id) {
            if (confirm('确定要删除这个入口吗？')) {
                entries = entries.filter(e => e.id !== id);
                renderEntries();
                showToast('入口已删除', 'success');
            }
        }

        // 打开添加对话框
        function openAddModal() {
            editingId = null;
            document.getElementById('modalTitle').textContent = '添加入口';
            document.getElementById('entryForm').reset();
            document.getElementById('modalOverlay').classList.add('show');
        }

        // 关闭对话框
        function closeModal(event) {
            if (!event || event.target.id === 'modalOverlay') {
                document.getElementById('modalOverlay').classList.remove('show');
            }
        }

        // 保存入口
        function saveEntry() {
            const name = document.getElementById('entryName').value;
            const url = document.getElementById('entryUrl').value;
            
            if (!name || !url) {
                showToast('请填写完整的入口信息', 'error');
                return;
            }

            const entry = {
                id: editingId || entries.length + 1,
                name: name,
                url: url,
                category: document.getElementById('entryCategory').value,
                icon: document.getElementById('entryIcon').value || '📦',
                description: document.getElementById('entryDescription').value,
                status: document.getElementById('entryStatus').value
            };

            if (editingId) {
                const index = entries.findIndex(e => e.id === editingId);
                entries[index] = entry;
                showToast('入口已更新', 'success');
            } else {
                entries.push(entry);
                showToast('入口已添加', 'success');
            }

            renderEntries();
            closeModal();
        }

        // 搜索和筛选
        document.getElementById('searchInput').addEventListener('input', debounce(renderEntries, 300));
        document.getElementById('categoryFilter').addEventListener('change', renderEntries);

        // 视图切换
        document.querySelectorAll('.view-toggle button').forEach(btn => {
            btn.addEventListener('click', () => {
                document.querySelectorAll('.view-toggle button').forEach(b => b.classList.remove('active'));
                btn.classList.add('active');
                const grid = document.getElementById('entriesGrid');
                if (btn.dataset.view === 'list') {
                    grid.style.gridTemplateColumns = '1fr';
                } else {
                    grid.style.gridTemplateColumns = 'repeat(auto-fill, minmax(300px, 1fr))';
                }
            });
        });

        // 初始渲染
        renderEntries();
    </script>
</body>
</html>

